package ldk.easytouch.example.menus;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;

import com.mikepenz.iconics.IconicsDrawable;

import ldk.easytouch.example.R;
import ldk.easytouch.utils.OSUtil;

/**
 * Created by ke on 16-9-16.
 */
public class MikepenzMenuItem extends AbstractMenuItem{

    private String mIconStr;
    private Context mContext;
    private boolean mCanDelete = true;

    private View.OnClickListener mOnClickListener;
    private View.OnLongClickListener mLongClickListener;
    public MikepenzMenuItem(Context context, String name, String iconStr) {
        super(name);
        mIconStr = iconStr;
        mContext = context;
    }

    public MikepenzMenuItem(Context context, String iconStr){
        this(context, "", iconStr);
    }

    public void setOnClickListener(View.OnClickListener mOnClickListener) {
        this.mOnClickListener = mOnClickListener;
    }

    public void setLongClickListener(View.OnLongClickListener mLongClickListener) {
        this.mLongClickListener = mLongClickListener;
    }

    public void setCanDelete(boolean canDelete){
        mCanDelete = canDelete;
    }

    @Override
    public void onSingleTapConfirmed() {
        if(mOnClickListener != null){
            mOnClickListener.onClick(null);
        }
    }

    @Override
    public boolean onLongPressed() {
        OSUtil.vibrator(mContext);
        return mLongClickListener != null && mLongClickListener.onLongClick(null);
    }

    @Override
    protected Drawable generateIcon() {
        return new IconicsDrawable(mContext)
                .icon(mIconStr)
                .color(mContext.getResources().getColor(R.color.snow1))
                .sizeDp(MENU_ITEM_SIZE);
    }

    public String getIconStr(){
        return mIconStr;
    }

    @Override
    public boolean canDelete() {
        return mCanDelete;
    }
}
